package com.kuang.dao;

import com.kuang.pojo.Department;
import com.kuang.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

@Repository
public class EmployeeDao {
    @Autowired
    private DepartmentDao departmentDao;
    private static Map<Integer, Employee> map;
    static {
        map=new HashMap<>();
        map.put(1001,new Employee(1001,"A1","2719746230@qq.com",0,new Department(101,"教研1")));
        map.put(1002,new Employee(1002,"A2","2719746230@qq.com",1,new Department(102,"教研2")));
        map.put(1003,new Employee(1003,"A3","2719746230@qq.com",0,new Department(103,"教研3")));
        map.put(1004,new Employee(1004,"A4","2719746230@qq.com",1,new Department(104,"教研4")));
        map.put(1005,new Employee(1005,"A5","2719746230@qq.com",1,new Department(105,"教研5")));
    }
    private static Integer innit=1006;
    public void addEmployee(Employee employee){
        if (employee.getId()==null){
            employee.setId(innit++);
        }
        employee.setDepartment(departmentDao.getDepartmentId(employee.getDepartment().getId()));
        map.put(employee.getId(), employee);
    }
    public void deleteEmployee(int id){
        map.remove(id);
    }
    public Collection<Employee> selectEmployee(){
        return map.values();
    }
    public Employee selectEmployeeId(int id){
        return map.get(id);
    }
}
